//出厂测试 程序

#include <stdint.h>
#include "FactoryTest.h"
#include "GN1621_Pin.h"
#include "GN1621_Parts_Num.h"
#include "APP_Main.h"


uint16_t Factory_Number = 0;
uint8_t Factory_Enable = 0;
uint8_t Factory_LCD_ONOFF = 1;

void Factory_EncoderKey_Handler(void)
{
    Buzzer_Encoder_Down();
    if(Fan_State.Feed == 0) 
	{
		HeaterFanOpen;
	}
    else HeaterFanClose;
}
void Factory_EncoderTurnR_Handler(void)
{
    Buzzer_Encoder_Down();
    if(Factory_Number < 999) Factory_Number += 111;
}
void Factory_EncoderTrunL_Handler(void)
{
    Buzzer_Encoder_Down();
    if(Factory_Number > 0) Factory_Number -= 111;
}

void Delay_16ms(void)
{
    uint16_t i;

    for (i = 0; i < 2500 * 16; i++)
    {
        
    }
}

void Factory_Main(void)
{

    //上电后,检测菜单键有效
    if (GPIO_ReadEncoderKey == 0x00)
    {
        Delay_16ms();
        Delay_16ms();
        Delay_16ms();
        if (GPIO_ReadEncoderKey == 0x00)
        {
            Delay_16ms();
            Delay_16ms();
            Delay_16ms();
            if (GPIO_ReadEncoderKey == 0x00)
            {
                HeaterFanOpen;
                IgniterOpen;
                ExhaustFanOpen;
                //编码器处理初始化
                Encoder_Key_Handler = Factory_EncoderKey_Handler;
                Encoder_TurnR_Handler = Factory_EncoderTurnR_Handler;
                Encoder_TurnL_Handler = Factory_EncoderTrunL_Handler;

                UI_System.ICO_WIFI = UI_ON;
                UI_System.ICO_Bluetooth = UI_ON;
                UI_System.ICO_Auger = UI_ON;
                UI_System.ICO_Fan = UI_ON;
                UI_System.ICO_Heating = UI_ON;
                UI_System.ICO_Error = UI_ON;
                UI_System.ICO_Cell = UI_ON;
                UI_System.Shine_WIFI = UI_ON;
                UI_System.Grill_Unit = Unit_F;
                Factory_Enable = 1;
                GN1621_ON(); 
                GN1621_RAM_Reset(0xff); 
                UI_System.LCD_State = UI_ON; 
                Key_Init();
                
                while (1)
                {
                    EncoderMain();

                    if(RTD[ADC_Meat1].status == Pt_Normal) Factory_Lcd_NumShow(UI_ProbeA, UI_System.ProbeA.Actual);
                    else Factory_Lcd_NumShow(UI_ProbeA, Factory_Number);
                    if(RTD[ADC_Meat2].status == Pt_Normal) Factory_Lcd_NumShow(UI_ProbeB, UI_System.ProbeB.Actual);
                    else Factory_Lcd_NumShow(UI_ProbeB, Factory_Number);
                    if(RTD[ADC_Meat3].status == Pt_Normal) Factory_Lcd_NumShow(UI_ProbeC, UI_System.ProbeC.Actual);
                    else Factory_Lcd_NumShow(UI_ProbeC, Factory_Number);  

                    if(RTD[ADC_Oven].status == Pt_Normal) Factory_Lcd_NumShow(UI_RTD, UI_System.RTD.Actual);
                    else Factory_Lcd_NumShow(UI_RTD, Factory_Number);
                    
                    Key_Main();
                }
            }
        }
    }
}
